package com.liwentao.seckill.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }
    private static String salt="liwentao";
    public static String inputPassToFromPass(String inputPass){
        String src= salt.charAt(0)+salt.charAt(2)+inputPass+salt.charAt(4)+salt.charAt(3);
        return md5(src);
    }
    public static String fromPassToDBPass(String fromPass,String salt){
        String src= salt.charAt(0)+salt.charAt(2)+fromPass+salt.charAt(4)+salt.charAt(3);
        return md5(src);
    }

    public static String inputPassToDBPass(String inputPass,String salt){
        String fromPass=inputPassToFromPass(inputPass);
        String dbPass=fromPassToDBPass(fromPass, salt);
        return dbPass;
    }

    public static void main(String[] args) {
        //6fb95fee60c9f59c08bf98df5c41be12
        System.out.println(inputPassToFromPass("KanoIA2989657"));
        System.out.println(fromPassToDBPass("9b3c57dea2b2d7171e6a7dc412375371", "31531"));
        System.out.println(inputPassToDBPass("KanoIA2989657", "31531"));
    }

}
